﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.Bliss.Services;

public partial class Test : BaseView
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        IPostService service = new PostService();
        var res = service.GetPosts(1);
        var data = res.DataCollection.ToList();
         //data = res.DataCollection.Where(p => p.ParentPostID.HasValue == false || p.ParentPostID.Value == 0).ToList();

        string html = "<table border=1>";
        foreach (var post in data)
        {
            html = html + String.Format("<tr><td>{0}</td><td>By: {1}</td><td>Children: {2}</td></tr>", post.Message, post.PostedBy == null ? 0 : post.PostedBy.ID, post.Comments == null ? 0 : post.Comments.Count());

            html = html + "<td>*</td><td colspan=2>";
            html = html + "<table border=1>";
            foreach (var comment in post.Comments)
            {
                html = html + String.Format("<tr><td>{0}</td><td>By: {1}</td>", comment.Message, comment.PostedBy == null ? 0 : comment.PostedBy.ID);
            }
            html = html + "</table>";
            html = html + "</td>";
        }
        html = html + "</table>";
        Response.Write(html);
    }
}